﻿using Abp.Runtime.Session;
using Abp.Timing.Timezone;
using Camc.Quality.DataExporting.Excel.EpPlus;
using Camc.Quality.Dto;
using Camc.Quality.Materials.Dto;
using Camc.Quality.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camc.Quality.Materials.MaterialsInterface
{
   public class MaterialsExportToExcel: EpPlusExcelExporterBase, IMaterialsExportToExcel
    {
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;

        public MaterialsExportToExcel(
            ITimeZoneConverter timeZoneConverter,
           // IAbpSession abpSession,
            ITempFileCacheManager tempFileCacheManager)
            : base(tempFileCacheManager)
        {
            _timeZoneConverter = timeZoneConverter;
           // _abpSession = abpSession;
        }
        public string ExportToFile(List<MaterialsContentDto>  materialsContentDtos)
        {
            return CreateExcelPackageLocal(
                "物料明细内容.xlsx",
                excelPackage =>
                {
                    var sheet = excelPackage.Workbook.Worksheets.Add(L("物料明细"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                        L("物料名称"),
                        L("物料代码"),
                        L("规格型号"),
                        L("物料类型名称"),
                        L("单位"),
                        //L("是否使用"),
                        //L("是否关键件"),
                        //L("是否标准件"),
                        //L("备注"),
                        //L("物料属性"),
                        //L("图号")
                        L("创建人"),
                        L("创建时间")
                        );

                    AddObjects(
                        sheet, 2, materialsContentDtos,
                        _ => _.MaterialName,
                        _ => _.MaterialNo,
                        _ => _.Model,
                        _ => _.MaterialTypeName,
                        _ => _.Unit,
                        //_ => _.IsUsed,
                        //_ => _.IsKeyPart,
                        //_ => _.IsStandard,
                        //_ => _.Remark,
                        //_ => _.MaterialProperty,
                        //_ => _.DrawingNo,
                        _=>_.CreateUser,
                        _=>_.CreationTime
                        //_ => _timeZoneConverter.Convert(_.CreationTime, _abpSession.TenantId, _abpSession.GetUserId())
                        );
                    //Formatting cells
                    var creationTimeColumn = sheet.Column(7);
                    creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd HH:mm:ss";

                    for (var i = 1; i <= 9; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }
                });
        }



    }
}
